package app

import (
	// "os"
	// "path/filepath"

	"github.com/jinzhu/configor"
)

/*
AppName = "灵小越"
AppPort = 4040
AppVersion = "0.0.1"
AppMode = "dev"
AutoCreateAdminAccount = "y" # y/n

[DB]
adapter = "mysql"
host = "localhost"
port = 3306
name = "chenrh"
user = "root"
password = "root"
*/

// AppConfig 读取全局配置文件配置信息
var AppConfig = struct {
	AppName                string `default:"AppName"`
	AppPort                uint   `default:"8080"`
	AppVersion             string `default:"0.0.0"`
	AppMode                string `default:"prod"`
	AutoCreateAdminAccount string `default:"y"`

	DB struct {
		Adapter  string `default:"mysql"`
		Name     string `default:"gowww"`
		Host     string `default:"localhost"`
		Port     uint   `default:"3306"`
		User     string `default:"root"`
		Password string `default:"root"`
	}
}{}

// var Root = os.Getenv("GOPATH") + "/src/gitee.com/chenrh/finego"

// LoadConfig 载入配置文件信息
func LoadConfig(tomlFilePath string) {
	if len(tomlFilePath) == 0 {
		tomlFilePath = "./conf/app.toml"
	}
	if err := configor.Load(&AppConfig, tomlFilePath); err != nil {
		panic(err)
	}
}
